use std::sync::{Arc, Barrier};
use std::thread;
fn main() {
    // Barrier
    let barrier = Arc::new(Barrier::new(3)); // 3
    //创建多线程
    let mut handles = vec![];
    for id in 0..3 {
        let barrier = Arc::clone(&barrier);
        let handle = thread::spawn(move || {
            //模拟一些工作
            println!("Thread {} working", id);
            thread::sleep(std::time::Duration::from_secs(id as u64));
            //线程到达同步点
            barrier.wait();
            //执行同步后的操作
            println!("Thread {} resumed", id);
        });
        handles.push(handle);
    }
    for handle in handles {
        handle.join().unwrap();
    }
}
